package com.zhang.activity;

import com.zhang.activity.CircleAdjustButton.OnCircleAdjustListener;
import com.zhang.activity.DiyDialog.OnDiyDialogListener;
import com.zhang.activity.FlyDialog.OnFlyDialogListener;
import com.zhang.little_sample.R;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListActivity extends Activity implements OnClickListener {
	private Button btnLiuShi;
	private Button btnHuaDong;
	private Button btnDengDai;
	private Button btnJianBian;
	private Button btnEveryStyle;
	private int msg = 2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list);
		initView();
	}

	private void initView() {
		btnDengDai = (Button) findViewById(R.id.btn_dengdai);
		btnDengDai.setOnClickListener(this);
		btnHuaDong = (Button) findViewById(R.id.btn_huadong);
		btnHuaDong.setOnClickListener(this);
		btnLiuShi = (Button) findViewById(R.id.btn_liushi);
		btnLiuShi.setOnClickListener(this);
		btnJianBian = (Button) findViewById(R.id.btn_jianbian);
		btnJianBian.setOnClickListener(this);
		btnEveryStyle = (Button) findViewById(R.id.btn_everystyle);
		btnEveryStyle.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_dengdai:
			Dialog dialog = createLoadingDialog(ListActivity.this, "Wait...");
			dialog.show();
			break;
		case R.id.btn_huadong:
			showHuaDongDialog();
			break;
		case R.id.btn_liushi:
			showLiuShiDialog();
			break;
		case R.id.btn_jianbian:
			showCircleDialog();
			break;
		case R.id.btn_everystyle:
			break;
		default:
			break;
		}
	}

	private void showCircleDialog() {
		CircleAdjustButton circleAdjustButton = new CircleAdjustButton(
				ListActivity.this, new OnCircleAdjustListener() {

					@Override
					public void back(int resultTag) {

					}
				});
		circleAdjustButton.show();
	}

	private void showHuaDongDialog() {
		FlyDialog dialog = new FlyDialog(ListActivity.this,
				new OnFlyDialogListener() {

					@Override
					public void back(int resultTag) {
						// TODO Auto-generated method stub
						msg = resultTag;
					}
				});
		dialog.show();
	}

	private void showLiuShiDialog() {
		DiyDialog dialog = new DiyDialog(this, "title",
				new OnDiyDialogListener() {

					@Override
					public void back(String name) {

					}
				});
		dialog.show();
	}

	public static Dialog createLoadingDialog(Context context, String msg) {
		LayoutInflater inflater = LayoutInflater.from(context);
		View v = inflater.inflate(R.layout.loading_dialog, null);
		LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);
		ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
		TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);
		AnimationDrawable animationDrawable = (AnimationDrawable) spaceshipImage
				.getBackground();

		tipTextView.setText(msg);
		Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);
		loadingDialog.setCancelable(true);// 不可以用“返回键”取消
		loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.MATCH_PARENT));
		animationDrawable.start();
		return loadingDialog;
	}
}
